#include <iostream>
#include <lemon/list_graph.h>
#include <lemon/lgf_reader.h>
#include <lemon/preflow.h>
#include <boost/archive/binary_iarchive.hpp>
#include <map>
#include <boost/serialization/map.hpp>
#include <cassert>
#include <cmath>
using namespace lemon;
int main() {
	std::ifstream fin("graph_dump.txt");
	ListDigraph digraph;
	ListDigraph::ArcMap<double> cap(digraph);
	ListDigraph::Node src, trg;
	digraphReader(digraph, fin)
		.arcMap("capacity", cap)
		.node("source", src)
		.node("target", trg)
		.run();
    
    std::ifstream s("map.oarchive", std::ios::binary);
    boost::archive::binary_iarchive ia(s);
    std::map<int, double> m;
    ia >> m;
    for(std::map<int, double>::iterator it=m.begin(); it!=m.end(); ++it){
        int arc_id = it->first;
        double arc_cap = it->second;
        ListDigraph::Arc arc = digraph.arcFromId(arc_id);
        assert(abs(arc_cap - cap[arc])<1e-5);
        cap[arc]= arc_cap;
    }
	Preflow<ListDigraph, ListDigraph::ArcMap<double> > preflow(digraph, cap, src, trg);
	preflow.run();

	Preflow<ListDigraph, ListDigraph::ArcMap<double> > preflow_second(digraph, cap, src, trg);
	bool is_succ = preflow_second.init(preflow.flowMap());
	std::cout << "init succ: " << is_succ << std::endl;
}
